package api

import (
	"longmen/server/config/global"
	_const "longmen/server/pkg/common/helper/const"
	"longmen/server/pkg/common/helper/util"
	grpc_client2 "longmen/server/pkg/grpc_client"
	"longmen/server/pkg/protobuf"
	pb "longmen/server/pkg/protobuf"

	"github.com/labstack/echo/v4"
)

func (base *Controller) LiveList6t(c echo.Context) error {
	r := &pb.LiveList6TReq{}
	if err := util.Json2Struct(c.Get("body").(string), r); err != nil {
		return util.BadParam(c, err)
	}
	if err := _const.Validate.Struct(r); err != nil {
		return util.BadParam(c, err)
	}
	ctx, cancel := base.GrpcWithTimeout()
	defer cancel()
	resp, err := grpc_client2.GrpcLiveServer.LiveList6T(ctx, r)
	if err != nil {
		global.Log.Errorf("%+v", resp, err)
		return util.BuildFail(c, _const.RPC_FAILED, err.Error(), err)
	}
	return util.BuildSuccess(c, resp, "")
}

func (base *Controller) LiveDetail6t(c echo.Context) error {
	r := &pb.LiveDetail6TReq{}
	if err := util.Json2Struct(c.Get("body").(string), r); err != nil {
		return util.BadParam(c, err)
	}
	if err := _const.Validate.Struct(r); err != nil {
		return util.BadParam(c, err)
	}
	ctx, cancel := base.GrpcWithTimeout()
	defer cancel()
	resp, err := grpc_client2.GrpcLiveServer.LiveDetail6T(ctx, r)
	if err != nil {
		global.Log.Errorf("%+v", resp, err)
		return util.BuildFail(c, _const.RPC_FAILED, err.Error(), err)
	}
	return util.BuildSuccess(c, resp, "")
}

func (base *Controller) AllAnchor6T(c echo.Context) error {
	ctx, cancel := base.GrpcWithTimeout()
	defer cancel()
	resp, err := grpc_client2.GrpcLiveServer.AllAnchor6T(ctx, &protobuf.Empty{})
	if err != nil {
		global.Log.Errorf("%+v", resp, err)
		return util.BuildFail(c, _const.RPC_FAILED, err.Error(), err)
	}
	return util.BuildSuccess(c, resp, "")
}
